<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>字典管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>


        <el-table :data="tableData" border  style="width: 100%"

        >
            <el-table-column
                    width="80">
            </el-table-column>
               <el-table-column prop="fabulousLimitCount" label="每人每天可点赞次数" sortable width="500">
            </el-table-column>


            <el-table-column label="操作" width="300">
                <template scope="scope">
                    <el-button size="small" type="primary"
                               @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                </template>
            </el-table-column>



            

        </el-table>



        <div>
            <el-dialog title="编辑字典" v-model="formVisible">
                <el-form :model="setting" :rules="rules" ref="setting">

                    <el-form-item  label="每人每天可点赞次数" prop="fabulousLimitCount">
                        <el-input-number v-model="setting.fabulousLimitCount"  :min="1" :max="1000"></el-input-number>
                    </el-form-item>
                </el-form>


                <div slot="footer" class="dialog-footer">
                    <el-button @click="formVisible = false">关闭</el-button>
                    <el-button type="primary" @click="handleSave('setting')">确 定</el-button>
                </div>
            </el-dialog>

        </div>


    </div>
</template>

<script>
    import { Loading } from 'element-ui';
    export default {
        data() {
            return {
                setting:{
                    settingId:"",
                    fabulousLimitCount:5
                },
                tableData:[],
                formVisible:false,
                rules: {

                    fabulousLimitCount: [
                        { required: true, message: '请填入每人每天可点赞次数' },{ type: 'number', message: '可点赞数为数字'}
                    ]



                }
            }
        },

        methods: {






            getData(){

                let self = this;
                let params = {

                };

                self.$req.pget(self.$api("Setting")+"getSettingList",self,function(res){
                    console.log(res.data.data);
                    self.tableData = res.data.data;

                },params,true)
            },
            handleEdit(index,row){
                let self = this;
                let params = {
                }

                self.$req.pget(self.$api("Setting")+"getSetting",self,function(res){
                    self.setting=res.data.data;
                    console.log(self.setting);

                },params,true)

                this.formVisible=true;
            },
            handleSave(formName){
                let self = this;
                self.$refs[formName].validate((valid) => {
                    console.log(valid);
                    if (valid) {
                        self.formVisible = false;
                        self.$req.post(self.$api("Setting")+"saveSetting",self,function(res){
                            self.getData();
                        },self.setting,true);
                    }
                });

            }


           



        },
        mounted:function(){
            this.getData();
        }
    }
</script>